var express = require('express');
var proxy = require('http-proxy-middleware');

var app = express();
app.all('*', function(req, res, next) {
    if (req.headers.origin) {
        res.header("Access-Control-Allow-Origin", req.headers.origin);
        res.header("Access-Control-Allow-Credentials", true)
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
        res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
    }
    next()
})

app.use('/oauthApp', proxy({target: 'ose.caiyun.feixin.10086.cn/', changeOrigin: true}));
// app.use('/emp/oauth2/v3/access_token', proxy({target: 'https://oauth.api.189.cn/', changeOrigin: true}));
// app.use('/ChinaTelecom/', proxy({target: 'http://api.189.cn/', changeOrigin: true}));
// app.use('/file/downloadFile.action', proxy({target: 'http://download.cloud.189.cn/', changeOrigin: true}));

app.listen(3000);